
# 导包
import requests
# 定义类
class DingTalk:
    # 定义初始化方法
    def __init__(self):
        self.header={"content":"application/json","charset":"utf-8"}
        self.url="https://oapi.dingtalk.com/robot/send?access_token=3ecb35cd9cc4b8521aea2bff462b5e26644553635461c550ba8ed2a9cc13d677"
    # 发送普通消息
    def send_msg(self,text):
        dic={
            "msgtype":"text",
            "text":{"content":text},
            "at":{
                "atMobiles":["+8613253491221","+8615037766529"],
                "isAtaLL": False
            }
        }
        res=requests.post(url=self.url,headers=self.header,json=dic)
        result=self.__judge(res.json())
        return result
    # 发送链接
    def send_link(self,text,link):
        dic={
            "msgtype":"link",
            "link":{
                "text": text,
                "title": "橙好登录模块测试报告,请查收",
                "messageUrl": link
            },
        }
        res = requests.post(url=self.url, headers=self.header, json=dic)
        result = self.__judge(res.json())
        return result
    # 私有化判断返回结果
    def __judge(self,res):
        if res["errcode"]==0 and res["errmsg"]=="ok":
            return True
        else:
            return False

if __name__ == '__main__':
    dt=DingTalk()
    print(dt.send_msg("测试"))
    print(dt.send_link("测试","http://www.baidu.com"))